package cn.edu.scau.cmi.xiaozhenlin.hibernate;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;

public class HibernateCtrl {
	Hibernate hibernate;
	String name;
	String id;

	@FXML
	private TextField et_id;

	@FXML
	private TextField et_name;

	@FXML
	private Label tv_id;

	@FXML
	private Label tv_name;

	@FXML
	private Button btn_c;

	@FXML
	private Button btn_d;

	@FXML
	private Button btn_r;

	@FXML
	private Button btn_u;

	@FXML
	private TextArea tv_show;

	@FXML
	void onCreate(ActionEvent event) {
		id = et_id.getText();
		name = et_name.getText();
		et_id.clear();
		et_name.clear();
		tv_show.setText("增加成功！！！");
		hibernate.create(id, name);
	}

	@FXML
	void onDelete(ActionEvent event) {
		id = et_id.getText();
		name = et_name.getText();
		et_id.clear();
		et_name.clear();
		tv_show.setText("删除成功！！！");
		hibernate.delete(id);
	}

	@FXML
	void onRetrieve(ActionEvent event) {
		id = et_id.getText();
		name = et_name.getText();
		et_id.clear();
		et_name.clear();
		tv_show.setText(hibernate.retrieve(id));
	}

	@FXML
	void onUpdate(ActionEvent event) {
		id = et_id.getText();
		name = et_name.getText();
		et_id.clear();
		et_name.clear();
		tv_show.setText("修改成功！！！");
		hibernate.update(id, name);
	}

	public void Init() {
		// TODO 自动生成的方法存根
		hibernate = new Hibernate();

	}

}
